local key = KEYS[1]
local id = tonumber(ARGV[1])
local price = tonumber(ARGV[2])
local number = tonumber(ARGV[3])
local result = redis.call("zrangebyscore", key, price, price)
if next(result) ~= nil then
    local data = cjson.decode(result[1])
    local pos
    for i, v in ipairs(data) do
        if v[1] == id then
            pos = i
        end
    end
    if pos ~= nil then
        data[pos][2] = number
    else
        table.insert(data, { id, number })
    end
    redis.call('zremrangebyscore', key, price, price)
    redis.call('zadd', key, price, cjson.encode(data))
else
    redis.call('zadd', key, price, cjson.encode({ { id, number } }))
end